/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package op.element;

import java.util.Calendar;
import op.Ligacao;

/**
 *
 * @author Jônatas
 */
public class LigacaoHorario implements Comparable<LigacaoHorario> {

    private int inicioLig;
    private int qtdeLigacoes;
    private long tempoTotal;
    private double valor;

    public void addLigacao(Ligacao lig) {

        Calendar cal = Calendar.getInstance();
        cal.setTime(lig.getDataOrigemLigacao());

        int inicio = cal.get(Calendar.HOUR_OF_DAY);

        if (inicio != inicioLig) {
            return;
        }

        qtdeLigacoes++;
        tempoTotal += lig.getDuracao().intValue();
        valor += lig.getCusto().doubleValue();

    }

    public LigacaoHorario(int inicioLig) {
        this.inicioLig = inicioLig;
    }

    public int getInicioLig() {
        return inicioLig;
    }

    public void setInicioLig(int inicioLig) {
        this.inicioLig = inicioLig;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final LigacaoHorario other = (LigacaoHorario) obj;
        if (this.inicioLig != other.inicioLig) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 59 * hash + this.inicioLig;
        return hash;
    }

    @Override
    public String toString() {

        String resp = "";

        if (inicioLig < 10) {
            resp = "0";
        }

        resp += inicioLig + ":00 - ";

        if ((inicioLig + 1) < 10) {
            resp += "0";
        }

        resp += (inicioLig + 1) + ":00";

        return resp;
    }

    public int getQtdeLigacoes() {
        return qtdeLigacoes;
    }

    public long getTempoTotal() {
        return tempoTotal;
    }

    public double getValor() {
        return valor;
    }

    public int compareTo(LigacaoHorario o) {
        return (this.inicioLig - o.inicioLig);
    }
}
